package com.qf.qfleadnewscommons.swagger;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
//启用swagger
@EnableSwagger2 //http://localhost:52601/swagger-ui/index.html 访问这个路径可以查看文档，并且支持在线测试
@EnableKnife4j  //http://localhost:52601/doc.html  访问这个路径可以查看文档，并且支持下载
public class SwaggerAutoConfiguration {

    //向spring中注入一个Docket对象

    @Bean
    public Docket docket(){
        Docket docket = new Docket(DocumentationType.OAS_30);

        //配置apinfo
        docket.apiInfo(new ApiInfo(
                "集云头条",
                "集云头条API文档",
                "1.0",
                "cdm",
                new Contact(
                        "cdm",
                        "http://www.cdm.com",
                        "cdm@1000phone.com"),
                "千锋",
                "http://www.mobiletrain.org/",
                new ArrayList<>()));

        //设置基于哪个包生成哪些api接口文档
        docket.groupName("集云头条API文档")
                .select()
                //扫描哪些包
                .apis(RequestHandlerSelectors.basePackage("com.qf"))
                //根据那些控制层接口生成文档
                .paths(PathSelectors.ant("/**"));

        return docket;
    }

}
